package modele.agent;

import modele.agent.interfaces.AgentAbstract;
import modele.cases.CaseConway;
import modele.cases.interfaces.CaseInterface;

public class AgentConway extends AgentAbstract {

	private boolean stateFuture;
	private boolean stateNow;
	private Float bornProb;

	public AgentConway(int id, Float bornProb) {

		this.id = id;
		this.bornProb = bornProb;
		double d = Math.random();
		stateNow = true;
		if (d > bornProb) {
			stateNow = false;
		}
	}

	@Override
	public void doStep() {
		int nbAliveNeighbours = agentCase.getNbAliveAround();
		if (stateNow == false) {
			if (nbAliveNeighbours == 3) {
				stateFuture = true;
			}
		} else {
			if (nbAliveNeighbours > 3 || nbAliveNeighbours < 2) {
				stateFuture = false;
			}
		}
	}

	@Override
	public void finalizeStep() {
		stateNow = stateFuture;
	}

	@Override
	public boolean isAlive() {
		return stateNow;
	}

}
